package cn.tedu.hospitalgroupproject.server.content.controller;


import cn.tedu.hospitalgroupproject.server.common.pojo.vo.PageData;
import cn.tedu.hospitalgroupproject.server.common.web.JsonResult;
import cn.tedu.hospitalgroupproject.server.content.pojo.entity.Appointment;
import cn.tedu.hospitalgroupproject.server.content.pojo.vo.AppointmentListVO;
import cn.tedu.hospitalgroupproject.server.content.pojo.vo.ClinicListVO;
import cn.tedu.hospitalgroupproject.server.content.service.IAppointmentService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/management/appointments/")
@Api(tags="1.5 管理部分-预约单管理")
public class AppointmentController {

    @Autowired
    private IAppointmentService appointmentService;

    public AppointmentController() {
        log.info("创建预约单控制对象");
    }

    @ApiOperation("查询预约单列表")
    @ApiOperationSupport(order = 220)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", dataType = "int"),
            @ApiImplicitParam(name = "queryType", value = "查询类型，当需要查询全部数据时，此参数值应该是all")
    })
    @RequestMapping("/list")
    public JsonResult listAppointment(Integer page, String queryType) {
        log.debug("开始处理【查询预约单列表】请求，页码：{}", page);
        if (page == null) {
            page = 1;
        }
        Integer pageNum = page > 0 ? page : 1;
        PageData<AppointmentListVO> pageData ;
        if ("all".equals(queryType)) {
            pageData = appointmentService.list(1, Integer.MAX_VALUE);
        } else {
            pageData = appointmentService.list(pageNum);
        }
        return JsonResult.ok(pageData);
    }

    @ApiOperation("根据预约时间查询预约单列表")
    @ApiOperationSupport(order = 221)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", dataType = "int"),
            @ApiImplicitParam(name = "queryType", value = "查询类型，当需要查询全部数据时，此参数值应该是all")
    })
    @RequestMapping("/{gmtCreate}/gmtCreate/list")
    public JsonResult listAppointmentByCreateTime(Integer page, String queryType,@PathVariable String gmtCreate) {
        log.debug("开始处理【根据预约创建时间查询预约单列表】请求，页码：{}", page);
        if (page == null) {
            page = 1;
        }
        Integer pageNum = page > 0 ? page : 1;
        PageData<AppointmentListVO> pageData ;
        if ("all".equals(queryType)) {
            pageData = appointmentService.listByCreateTime(1, Integer.MAX_VALUE,gmtCreate);
        } else {
            pageData = appointmentService.listByCreateTime(pageNum,gmtCreate);
        }
        return JsonResult.ok(pageData);
    }

    @ApiOperation("根据问诊时间查询预约单列表")
    @ApiOperationSupport(order = 230)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", dataType = "int"),
            @ApiImplicitParam(name = "queryType", value = "查询类型，当需要查询全部数据时，此参数值应该是all")
    })
    @RequestMapping("/{visitTime}/visitTime/list")
    public JsonResult listAppointmentByVisitTime(Integer page, String queryType,@PathVariable String visitTime) {
        log.debug("开始处理【根据问诊时间查询预约单列表】请求，页码：{},请求类型:{},问诊时间:{}", page,queryType,visitTime);
        if (page == null) {
            page = 1;
        }
        Integer pageNum = page > 0 ? page : 1;
        PageData<AppointmentListVO> pageData ;
        if ("all".equals(queryType)) {
            pageData = appointmentService.listByVisitTime(1, Integer.MAX_VALUE,visitTime);
        } else {
            pageData = appointmentService.listByVisitTime(pageNum,visitTime);
        }
        return JsonResult.ok(pageData);
    }

    @ApiOperation("根据医生姓名查询预约单列表")
    @ApiOperationSupport(order = 230)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", dataType = "int"),
            @ApiImplicitParam(name = "queryType", value = "查询类型，当需要查询全部数据时，此参数值应该是all")
    })
    @RequestMapping("/{doctorName}/doctorName/list")
    public JsonResult listAppointmentByDoctorName(Integer page, String queryType,@PathVariable String doctorName) {
        log.debug("开始处理【根据医生姓名查询预约单列表】请求，页码：{},请求类型:{},医生姓名:{}", page,queryType,doctorName);
        if (page == null) {
            page = 1;
        }
        Integer pageNum = page > 0 ? page : 1;
        PageData<AppointmentListVO> pageData ;
        if ("all".equals(queryType)) {
            pageData = appointmentService.listByDoctorName(1, Integer.MAX_VALUE,doctorName);
        } else {
            pageData = appointmentService.listByDoctorName(pageNum,doctorName);
        }
        return JsonResult.ok(pageData);
    }
}
